package com.gears_software.bbnetwork.activitys;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.annotations.sharedpreferences.Pref;

import android.app.Activity;
import android.content.Intent;
import android.view.Window;
import android.widget.ImageView;

import com.avos.avoscloud.AVAnalytics;
import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.utlis.ActivityUtils;
import com.gears_software.bbnetwork.utlis.BBNetworkSharedPref_;
import com.gears_software.bbnetwork.utlis.ToastUI;
import com.gears_software.common.net.NetworkUtil;

/**
 * 我的页面
 * @author DY-PC
 *
 */
@EActivity(R.layout.activity_my)
@WindowFeature(Window.FEATURE_NO_TITLE)
public class MyActivity extends Activity {

	@ViewById
	ImageView image_renzheng;// 认证图标

	@Pref
	BBNetworkSharedPref_ sp;
	
	@Bean
	ToastUI toast;

	@AfterViews
	void onCreate() {
		String status = sp.status().get();// 用户认证状态
		ActivityUtils.listActivity.add(this);
		if (status != null && status.equals("2")) {
			image_renzheng.setImageResource(R.drawable.bb_renzhenghuang);
		}
	}

	// 回退
	@Click
	void iamge_back() {
		finish();
	}

	// 报单记录
	@Click
	void baodan_record() {
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		Intent intent = new Intent(this, BaoDanListActivity_.class);
		startActivity(intent);
	}
	
	@UiThread
	void showTxt(String txt){
		toast.ShowToast(txt);
	}
	
	//我的推荐码
	@Click
	void recommend_code(){
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		Intent intent = new Intent(this, RecommendActivity_.class);
		startActivity(intent);
	}
	
	//我的奖励记录
	@Click
	void rewards_record(){
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		Intent intent = new Intent(this, RecommendRewardzActivity_.class);
		startActivity(intent);
	}

	// 我的信息
	@Click
	void myinfo() {
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		Intent intent = new Intent(this, MyInfoActivity_.class);
		startActivity(intent);
	}

	// 我的银行卡
	@Click
	void mycard() {
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		String hasBankCard = sp.hasBankCard().get();
		if (hasBankCard.equals("1")) {
			Intent intent = new Intent(this, MyCardActivity_.class);
			startActivity(intent);
		} else {
			Intent intent = new Intent(this, PinlessCardActivity_.class);
			startActivity(intent);
		}

	}

	@Click
	void setpwd() {
		boolean isnet = NetworkUtil.checkNetworkInfo(this);
		if(!isnet){
			showTxt("请检查网络是否正常！");
			return;
		}
		Intent intent = new Intent(this, SetPwdActivity_.class);
		startActivity(intent);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		AVAnalytics.onResume(this);
		String status = sp.status().get();// 用户认证状态
		if (status != null && status.equals("2")) {
			image_renzheng.setImageResource(R.drawable.bb_renzhenghuang);
		}
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AVAnalytics.onPause(this);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		ActivityUtils.listActivity.remove(this);
	}
}
